package org.come.Frame;

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.plaf.basic.BasicInternalFrameUI;

import org.come.Jpanel.PartnerArenaMainPanel;
import org.come.until.FormsManagement;
import org.come.until.MessagrFlagUntil;
import org.come.until.Music;

import com.tool.tcpimg.UIUtils;

/**
 * @author HGC<br>
 * @time 2020年3月19日 下午2:59:08<br>
 * @class 类名:PartnerArenaJframe 伙伴竞技主面板 编号:5<br>
 */
public class PartnerArenaJframe extends JInternalFrame implements MouseListener {
    private static PartnerArenaMainPanel partnerArenaMainPanel;
    private int first_x;// x、y坐标
    private int first_y;

    public static PartnerArenaJframe getPartnerArenaJframe() {
        return (PartnerArenaJframe)FormsManagement.getInternalForm(5).getFrame();
    }

    public PartnerArenaJframe() {
        this.add((Component)(PartnerArenaJframe.partnerArenaMainPanel = new PartnerArenaMainPanel()));
        this.setBorder(BorderFactory.createEmptyBorder());// 去除内部窗体的边框
        ((BasicInternalFrameUI)this.getUI()).setNorthPane(null);
        this.setBounds(300, 150, 300, 210);// 设置窗口出现的位置
        this.setBackground(UIUtils.Color_BACK);
        this.pack();
        this.setVisible(false);
        this.setDefaultCloseOperation(3);
        this.addMouseListener((MouseListener)this);
        this.addMouseMotionListener(new MouseMotionListener() {// 判断窗口移动的位置

            @Override
            public void mouseMoved(final MouseEvent e) {
                if (MessagrFlagUntil.ImgFlagImg.equals(MessagrFlagUntil.MOUSE13)) {
                    MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
                }
            }

            @Override
            public void mouseDragged(final MouseEvent e) {
                if (PartnerArenaJframe.this.isVisible()) {
                    final int x = e.getX() - PartnerArenaJframe.this.first_x;
                    final int y = e.getY() - PartnerArenaJframe.this.first_y;
                    PartnerArenaJframe.this.setBounds(x + PartnerArenaJframe.this.getX(), y + PartnerArenaJframe.this.getY(), PartnerArenaJframe.this.getWidth(), PartnerArenaJframe.this.getHeight());
                }
            }
        });
    }

    @Override
    public void mouseClicked(final MouseEvent e) {
    }

    @Override
    public void mousePressed(final MouseEvent e) {
        FormsManagement.showForm(5);
        // 关闭按钮
        // 开启窗口音效
        Music.addyinxiao("关闭窗口.mp3");
        // 打开了窗体
        if (e.isMetaDown()) {// 检测鼠标右键单击
            FormsManagement.HideForm(5);
        }
        else {
            FormsManagement.Switchinglevel(5);
        }
        this.first_x = e.getX();
        this.first_y = e.getY();
    }

    @Override
    public void mouseReleased(final MouseEvent e) {
    }

    @Override
    public void mouseEntered(final MouseEvent e) {
    }

    @Override
    public void mouseExited(final MouseEvent e) {
    }

    public PartnerArenaMainPanel getPartnerArenaMainPanel() {
        return PartnerArenaJframe.partnerArenaMainPanel;
    }

    public void setPartnerArenaMainPanel(final PartnerArenaMainPanel partnerArenaMainPanel) {
        PartnerArenaJframe.partnerArenaMainPanel = partnerArenaMainPanel;
    }

    public int getFirst_x() {
        return this.first_x;
    }

    public void setFirst_x(final int first_x) {
        this.first_x = first_x;
    }

    public int getFirst_y() {
        return this.first_y;
    }

    public void setFirst_y(final int first_y) {
        this.first_y = first_y;
    }
}